import { reqClassInfo } from '@/api/student';
import { useStudentStore } from '../../../../stores/modules/studentStore';
const studentStore = useStudentStore();
const compress = (fileObj, callback) => {
    try {
        const image = new Image();
        image.src = URL.createObjectURL(fileObj);
        image.onload = function () {
            const that = this;
            // 默认按比例压缩
            let w = that.width;
            let h = that.height;
            const scale = w / h;
            w = fileObj.width || w;
            h = fileObj.height || w / scale;
            let quality = 0.7; // 默认图片质量为0.7
            // 生成canvas
            const canvas = document.createElement('canvas');
            const ctx = canvas.getContext('2d');
            // 创建属性节点
            const anw = document.createAttribute('width');
            anw.nodeValue = w;
            const anh = document.createAttribute('height');
            anh.nodeValue = h;
            canvas.setAttributeNode(anw);
            canvas.setAttributeNode(anh);
            ctx.drawImage(that, 0, 0, w, h);
            // 图像质量
            if (
                fileObj.quality &&
                fileObj.quality <= 1 &&
                fileObj.quality > 0
            ) {
                quality = fileObj.quality;
            }
            // quality值越小，所绘制出的图像越模糊
            const data = canvas.toDataURL('image/jpeg', quality);
            // 压缩完成执行回调
            const newFile = convertBase64UrlToBlob(data);
            callback(newFile);
        };
    } catch (e) {}
};
export const getClassInfo = async () => {
    const result = await reqClassInfo(studentStore.studentNum);
    if (result.resultCode == 200) {
        if (!result.data.parentPhone) {
            ElMessage({
                type: 'error',
                message: '您还没有在学籍系统填写家长电话，无法请假'
            });
            router.push('/student/index');
        }
    }
    return result.data;
};
